# -*- coding: utf-8 -*-
# author: AZJ
# date: 2024/11/6
# 假如命运扼住了你的咽喉，你就去挠她的咯吱窝
import random
from datetime import datetime
# 购物：
#         1.用户的账户里有钱
#         2.用户可推一个空购物车进商场
#         3.开始购物，将自己想要的商品添加购物车
#         4.打印购物小条
#
# 程序和数据流程梳理分析：
# 	购前：
# 		钱要有：money
# 		有足够商品：列表来存储list
# 		有购物车：列表list
#
# 	购中：
# 		是否有这个商品：
# 			有
# 				钱够不够：
# 					够：
# 						添加到购物车！
# 						钱减去商品价格！
# 						恭喜，购买成功！您的卡余额还剩xxx
# 					不够：
# 						穷鬼，钱不够！请到其他超市购买！
# 			没有：
# 				没有这个商品，别瞎弄！
# 	购后：
# 		输入Q，q: 退出：
# 		打印购物小条！
'''customer_money = 10000
goods_list = ["东风-41", "歼30", "歼20", "巨浪-2", "辽宁号", "山东舰", "福建舰"]
goods_price = [1000, 3000, 2000, 1000, 5000, 5000, 5000]
shopping_cart = []
shopping_price = []
while 1:
    goods = input("请输入你想要购买的商品>>")
    if goods.upper() == 'Q':
        if shopping_cart:
            print("您的购物小票如下: ")
            print("商品名称\t\t商品价格")
            for i in range(len(shopping_cart)):
                print(goods_list[i], "\t\t", goods_price[i])
        else:
            print("您的购物车为空")
        break
    # print(goods.upper())
    if goods.upper() in goods_list:
        price = 0
        for index,value in enumerate(goods_list):
            if goods == value:
                price = goods_price[index]
        if price > customer_money:
            print("穷鬼，钱不够！请到其他超市购买！")
        elif price <= customer_money:
            shopping_cart.append(goods)
            shopping_price.append(price)
            customer_money -= price
            print("恭喜，购买成功！您的卡余额还剩: ", customer_money)
    else:
        print("没有这个商品，别瞎弄！")'''

# 1.现在用户在进商场之前需要从10张优惠券中，随机抽取一张优惠券。
# 比如抽到一个空凋的8折优惠券，后面在购物的过程中，空凋就可以按照8折后的价格来购买。

# 3.添加退货功能。在购买途中，某个商品不要了，退回到购物架中！
customer_money = 10000
goods_list = ["东风-41", "歼30", "歼20", "巨浪-2", "辽宁号", "山东舰", "福建舰"]
goods_price = [1000, 3000, 2000, 1000, 5000, 5000, 5000]
shopping_cart = []
shopping_price = []
shopping_date = []
coupon_list = ["东风-41减免50%", "东风-41减免20%", "东风-41减免30%", "歼30减免20%",
               "歼20减免20%", "巨浪-2减免20%", "辽宁号减免20%", "山东舰减免20%",
               "福建舰减免20%", "福建舰减免30%"]
a = random.randint(0,10)
coupon = coupon_list[a]
print("您抽取到: ", coupon, "优惠券! ")
if "东风-41" in coupon:
    if "50%" in coupon:
        goods_price[0] = 1000*0.5
    elif "20%" in coupon:
        goods_price[0] = 1000*0.8
    elif "30%" in coupon:
        goods_price[0] = 1000*0.7
elif "歼30" in coupon:
    goods_price[1] = 3000*0.8
elif "歼20" in coupon:
    goods_price[2] = 2000*0.8
elif "巨浪-2" in coupon:
    goods_price[3] = 1000*0.8
elif "辽宁号" in coupon:
    goods_price[4] = 5000*0.8
elif "山东舰" in coupon:
    goods_price[5] = 5000*0.8
elif "福建舰" in coupon:
    if "20%" in coupon:
        goods_price[6] = 5000*0.8
    elif "30%" in coupon:
        goods_price[6] = 5000*0.7

print("请输入你想要购买的商品(输入q或Q退出)")
while 1:
    goods = input("(退货输入t或T)>>")
    if goods.upper() == 'Q':
        # 2.优化购物小条的人性化打印。
        # 	购物时间，卡余额，购物数量，购买总商品的价值。
        if shopping_cart:
            print("您的购物小票如下: ")
            print("商品名称\t\t商品价格\t\t购买时间")
            sum_price = 0
            for i in range(len(shopping_cart)):
                print(goods_list[i], "\t\t", goods_price[i], "\t\t", shopping_date[i])
                sum_price += goods_price[i]
            print("购买总商品价格: ", sum_price)
            print("卡中余额为: ",customer_money)
        else:
            print("您的购物车为空")
        break
    # print(goods.upper())
    elif goods.upper() == 'T':
        print("您当前的购物车有以下货物")
        t_list = []
        for index,value in enumerate(shopping_cart):
            print(index+1, value)
            t_list.append(index+1)
        t_num = int(input("请选择退货序号>>"))
        if t_num in t_list:
            print("移除", shopping_cart[t_num-1], "...")
            shopping_cart.pop(t_num-1)
            customer_money += shopping_price[t_num-1]
            shopping_price.pop(t_num-1)
            shopping_date.pop(t_num-1)
            print("移除成功")
        else:
            print("没有这个序号，别瞎弄！")
    if goods.upper() in goods_list:
        price = 0
        for index,value in enumerate(goods_list):
            if goods == value:
                price = goods_price[index]
        if price > customer_money:
            print("穷鬼，钱不够！请到其他超市购买！")
        elif price <= customer_money:
            shopping_cart.append(goods)
            shopping_price.append(price)
            now = datetime.now()
            shopping_date.append(now.strftime("%Y-%m-%d"))
            customer_money -= price
            print("恭喜，购买成功！您的卡余额还剩: ", customer_money)
    else:
        print("没有这个商品，别瞎弄！")